<template>
  <rx-dialog @handOk="onOk" @cancel="cancel">
    <comment ref="current" :isDialog="isDialog" :is="currentView" :boDefId="boDefId" :listId="listId" :rowEdit="rowEdit" :layerid="layerid" :curFields="curFields" :destroy="destroy"></comment>
  </rx-dialog>
</template>

<script>
    import {RxDialog, Util} from "@lowcode/jpaas-common-lib";
    import renderConfigs from '../../../../api/form/core/renderconfig';
    export default {
      name: "RenderConfig",
      components: {RxDialog},
      props:["render","curFields","layerid","destroy","listId","rowEdit","boDefId"],
      data(){
        return {
          currentView:''
        }
      },
      computed:{
        current(){
          return this.$refs.current;
        },
        isDialog(){
            if (this.$route.query){
                return this.$route.query.isDialog
            }
        }
      },
      created() {
          let renderView=renderConfigs['renderConfig_'+this.render.renderType.toLowerCase()];

          this.currentView=renderView;
      },
      mounted(){
        this.setData();
      },
      methods:{
        onOk(e){
          var self=this;
          if(this.current.validate(()=>{
            Util.closeWindow(self, "ok");
          },e));
        },
        cancel(){
          Util.closeWindow(this,"cancel");
        },
        setData() {
          var renderConf=this.render.renderConf;
          if(!renderConf) renderConf="{}";
          renderConf = JSON.parse(renderConf);
          renderConf.field=this.render.field;
          if(renderConf.btnList){
              renderConf.btnList = renderConf.btnList.map(item=>{
                  if(item.defaultBtn && !item.type){
                      item['type']='';
                      item['config']='';
                  }else if(!item.defaultBtn && !item.type){
                      item['type']='custom';
                      item['config']='';
                  }
                  return item;
              })
          }

          this.current.setData(renderConf, this.curFields,this.listId,this.rowEdit);
        },
        getData(){
          return this.current.getData();
        }
      }
    }
</script>

<style scoped>

</style>